/**
 * @ClassName LC2614
 * @Author ykx
 * @Date 2024/3/22 8:24
 * @Version 1.0
 */
public class LC2614 {
    public int diagonalPrime(int[][] nums) {
        int result = 0;
        for (int i = 0; i < nums.length; i++) {
            if (result < nums[i][i] && isPrime(nums[i][i])) {
                result = nums[i][i];
            }
            if (result < nums[i][nums.length - 1 - i] && isPrime(nums[i][nums.length - 1 - i])) {
                result = nums[i][nums.length - 1 - i];
            }
        }
        return result;
    }

    public boolean isPrime(int n) {
        if (n == 0 || n == 1) {
            return false;
        }
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }

}
